package com.example.headlines;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.headlines.activity.BaseActivity;
import com.example.headlines.activity.HomeActivity;
import com.example.headlines.activity.LoginActivity;
import com.example.headlines.activity.RegisterActivity;
import com.example.headlines.databinding.ActivityMainBinding;
import com.example.headlines.util.StringUtils;

public class MainActivity extends BaseActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navigateTo(LoginActivity.class);
            }
        });

        binding.btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navigateTo(RegisterActivity.class);
            }
        });
    }

    @Override
    protected void initData() {
        if (!StringUtils.isEmpty(getStringFromSp("token"))) {
           navigateTo(HomeActivity.class);
           finish();
        }
    }

}